<template>
  <div class="app-container">
    <el-card>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="票据冲红" name="first">
          <el-form ref="form" :model="form" label-width="120px">
            <el-row>
              <el-col :span="8">
                <el-form-item label="票据代码" prop="invoiceCode">
                  <el-input placeholder="请输入票据代码" v-model="form.invoiceCode"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="票据号码" prop="invoiceNumber">
                  <el-input placeholder="请输入票据号码" v-model="form.invoiceNumber"/>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="经办人" prop="name">
                  <el-input v-model="form.handledBy=realname" :disabled="true"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="冲红原因" prop="reason">
                <el-input type="textarea" :rows="4" placeholder="请输入冲红原因" v-model="form.reason"/>
              </el-form-item>
            </el-row>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">冲红</el-button>
              <el-button @click="onCancel">重置</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="冲红记录" name="second">
          <ResetBillForm></ResetBillForm>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import {postAction} from "../../api/manage";
import ResetBillForm from './modules/ResetBillForm'
import {mapGetters} from 'vuex'
export default {
  components: {
    ResetBillForm
  },
  computed: {
    ...mapGetters([
      'realname'
    ])
  },
  data() {
    return {
      activeName: 'first',
      form: {
        invoiceCode:'',//票据代码
        invoiceNumber:'',//票据号码
        handledBy: '',//经办人
        reason: '' //冲红原因
      },
      url: {
        resetBill: '/nmyx/leantech/redOffset-bill' //票据冲红
      }
    }
  },
  methods: {
    onSubmit() {
      postAction(this.url.resetBill,this.form).then(res =>{
        console.log('resetbill',res)
        if (res.code == 'SUCCESS'){
          this.$message(res.message)
          this.$refs['form'].resetFields()
        } else {
          this.$message({message: '操作失败, ' + res.message})
        }
      }).catch(err =>{
        this.$message({message: '红冲失败, ' + res.message, type: 'error'})
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
      this.$refs['form'].resetFields()
    },
    handleClick(tab, event) {
      console.log(tab, event);
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

